<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="订单编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderNum">
              <a-input v-model="model.orderNum" placeholder="请输入订单编号" disabled></a-input>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="商品id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="goodId">
              <a-input v-model="model.goodId" placeholder="请输入商品id" disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商品名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="goodName">
              <a-input v-model="model.goodName" placeholder="请输入商品名称" disabled></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="订单状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderType">
              <!-- <a-input v-model="model.orderType" placeholder="请输入订单状态(1未付款2,已付款，3取消)" disabled></a-input> -->
              <a-select v-model="model.orderType" placeholder="请选择订单状态" disabled>
                <a-select-option label="待接单" value="SUCCESS">待接单</a-select-option>
                <a-select-option label="转入退款" value="REFUND">转入退款</a-select-option>
                <a-select-option label="未支付" value="NOTPAY">未支付</a-select-option>
                <a-select-option label="已关闭" value="CLOSED">已关闭</a-select-option>
                <a-select-option label="已撤销" value="REVOKED">已撤销</a-select-option>
                <a-select-option label="用户支付中" value="USERPAYING">用户支付中</a-select-option>
                <a-select-option label="支付失败" value="PAYERROR">支付失败</a-select-option>
                <a-select-option label="服务中" value="1">服务中</a-select-option>
                <a-select-option label="已完成" value="2">已完成</a-select-option>
                <a-select-option label="拒绝接单" value="3">拒绝接单</a-select-option>
                <a-select-option label="待退款" value="4">待退款</a-select-option>
                <a-select-option label="拒绝退款" value="5">拒绝退款</a-select-option>
                <a-select-option label="退款成功" value="6">退款成功</a-select-option>
                <a-select-option label="退款成功" value="REFUND_SUCCESS">退款成功</a-select-option>
                <a-select-option label="退款中" value="REFUND_PROCESSING">退款中</a-select-option>
                <a-select-option label="退款异常" value="REFUND_ABNORMAL">退款异常</a-select-option>
                <a-select-option label="退款关闭" value="REFUND_CLOSED">退款关闭</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="定金金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymentMoney">
              <a-input-number v-model="model.paymentMoney" placeholder="请输入定金金额" style="width: 100%" disabled />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalMoney">
              <a-input-number v-model="model.totalMoney" placeholder="请输入总金额" style="width: 100%" disabled />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="支付时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymentTime">
              <j-date placeholder="请选择支付时间" v-model="model.paymentTime" :show-time="true"
                date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" disabled />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="预计完成时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="completeTime">
              <a-input v-model="model.completeTime" placeholder="请输入预计完成时间" disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24" v-if="model.user">
            <a-form-model-item label="用户手机号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phone">
              <a-input-number v-model="model.user.phone" placeholder="请输入用户手机号" style="width: 100%" disabled />
            </a-form-model-item>
          </a-col>
          <a-col :span="24" v-if="model.user">
            <a-form-model-item label="用户名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="username">
              <a-input-number v-model="model.user.username" placeholder="请输入用户名称" style="width: 100%" disabled />
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="经纬度(经度)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="longitude">
              <a-input v-model="model.longitude" placeholder="请输入经纬度(经度)" disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="经纬度(纬度)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="latitude">
              <a-input v-model="model.latitude" placeholder="请输入经纬度(纬度)" disabled></a-input>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24">
            <a-form-model-item label="服务地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="position">
              <a-input v-model="model.position" placeholder="请输入服务地址" disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="服务地址地图" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="position"
              :disabled="false">
              <div id="map" style="width:450px;height:200px;background-color: pink;"></div>
              <!-- <button style="margin-top: 10px;">切换全屏</button> -->
              <a-button type="primary" @click="toggleFullScreen">地图切换全屏</a-button>
            </a-form-model-item>
          </a-col>

          <!-- <a-col :span="24">
            <a-form-model-item label="是否结算" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="settlement">
              <a-radio-group v-model="model.settlement" placeholder="请选择状态">
                <a-radio value="1">否</a-radio>
                <a-radio value="2">是</a-radio>
              </a-radio-group>
            </a-form-model-item>
          </a-col> -->
          <a-col :span="24" v-if="model.orderDetailsList">
            <a-form-model-item label="服务名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderDetailsList">
              <!-- <a-input-number v-model="model.orderDetailsList" placeholder="请输入用户名称" style="width: 100%" disabled /> -->
              <!-- <a-checkbox-group> -->
              <a-checkbox v-for="item in model.orderDetailsList" :checked="true">{{
    item.serviceName
  }} {{ item.num }} {{ model.typeService == '2' ? item.unit : '小时' }}</a-checkbox>
              <!-- </a-checkbox-group> -->
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import { jsonp } from 'vue-jsonp'
export default {
  name: 'MachineOrderForm',
  components: {
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
      },
      url: {
        add: "/order/machineOrder/add",
        edit: "/order/machineOrder/edit",
        queryById: "/order/machineOrder/queryById"
      },
      // 替换为你的腾讯地图API密钥  
      tencentMapKey: 'BANBZ-VEQC2-24OUC-CHMOJ-YRKSH-KGFXO',
      isFullScreen: false,
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));

  },
  methods: {
    add() {
      this.edit(this.modelDefault);
    },
    edit(record) {
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }
      })
    },
    ReceivingOrders() {
      // console.log(this.visible);
      this.confirmLoading = true;
      this.$refs.modalForm.disableSubmit = true;
      // this.visible = true;
    },
    //地图
    initMap() {
      // 定义地图中心点坐标
      const center = new window.TMap.LatLng(this.model.latitude, this.model.longitude);
      // 定义map变量，调用 TMap.Map() 构造函数创建地图
      const map = new window.TMap.Map(document.getElementById('map'), {
        center: center, // 设置地图中心点坐标
        zoom: 15, // 设置地图缩放级别
        pitch: 20, // 设置俯仰角
        rotation: 0 // 设置地图旋转角度
      });
      new window.TMap.MultiMarker({
        map: map,
        //点标记数据数组
        geometries: [
          {
            id: '1', //点标记唯一标识，后续如果有删除、修改位置等操作，都需要此id
            styleId: 'myStyle', //指定样式id
            position: new window.TMap.LatLng(this.model.latitude, this.model.longitude), //点标记坐标位置
            properties: {
              //自定义属性
              title: '位置'
            }
          }
        ]
      });
    },
    //全屏
    toggleFullScreen() {
      if (this.isFullScreen) {
        // 退出全屏，恢复正常大小
        if (document.exitFullscreen) {
          document.exitFullscreen();
        }
        this.isFullScreen = false;
      } else {
        // 进入全屏
        const element = document.getElementById('map');
        if (element.requestFullscreen) {
          element.requestFullscreen();
        }
        this.isFullScreen = true;
      }
    },
  },
  mounted() {
    setTimeout(() => {
      this.$nextTick(() => {
        this.initMap();
      });
    }, 1000)
  }
}
</script>